#pragma once
#include <vector>
#include <map>
#include <functional>
#include "../Headers/types.h"
#include "../Headers/utf8.h"
#include "../Headers/config.h"
#include "gui.window.h"

namespace TOB {
  class UIBrowser: public UIWindow {
   public:
    UIBrowser(uint16 x, uint16 y, uint16 w, uint16 h, Config &c);
    ~UIBrowser();

    void focus();
    void setPage(std::string &page);

    void moveX(int8 direction);
    void moveY(int8 direction);

    // Event
    std::function<void(std::string&)> eventLink;

   protected:
    void render(String page);
    void print();
    void parseTag(String tag);

    // Pixel
    typedef struct {
      Char ch;
      Color::Type color;
      uint32 link;
    } BPixel;

    // Containers
    String splitter;
    Config &code;
    std::map<String, Color::Type> colors;
    std::vector<std::vector<BPixel>> pixelMap;
    std::vector<std::string> links;

    // Stacks
    std::vector<Color::Type> colorStack;
    std::vector<uint32> linkStack;

    // Iterators
    uint16 x;
    uint32 y, iter;
    bool ignore, skip, running;
    uint32 scrollX, scrollY;
  };
}
